<?php
add_action('init', 'myStartSession', 1);

function myStartSession() {
    session_start();
}

add_filter('post_gallery', 'my_post_gallery', 10, 2);

function my_post_gallery($output, $attr) {
    global $post, $wp_locale;
    static $instance = 0;
    $instance++;
    if (isset($attr['orderby'])) {
        $attr['orderby'] = sanitize_sql_orderby($attr['orderby']);
        if (!$attr['orderby'])
            unset($attr['orderby']);
    }
    extract(shortcode_atts(array('order' => 'ASC', 'orderby' => 'menu_order ID', 'id' => $post->ID, 'itemtag' => 'dl', 'icontag' => 'dt', 'captiontag' => 'dd', 'columns' => 3, 'size' => 'thumbnail', 'include' => '', 'exclude' => ''), $attr));
    $id = intval($id);
    if ('RAND' == $order)
        $orderby = 'none';
    if (!empty($include)) {
        $include = preg_replace('/[^0-9,]+/', '', $include);
        $_attachments = get_posts(array('include' => $include, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby));
        $attachments = array();
        foreach ($_attachments as $key => $val) {
            $attachments[$val->ID] = $_attachments[$key];
        }
    } elseif (!empty($exclude)) {
        $exclude = preg_replace('/[^0-9,]+/', '', $exclude);
        $attachments = get_children(array('post_parent' => $id, 'exclude' => $exclude, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby));
    } else {
        $attachments = get_children(array('post_parent' => $id, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby));
    }
    if (empty($attachments))
        return '';
    if (is_feed()) {
        $output = "n";
        foreach ($attachments as $att_id => $attachment)
            $output .= wp_get_attachment_link($att_id, $size, true) . "n";
        return $output;
    }


    $categorias = get_the_category($post->ID);

    if ($categorias) {
        foreach ($categorias as $categoria) {
            if ($categoria->slug == "tips-de-disenio") {
                $itemtag = tag_escape($itemtag);
                $captiontag = tag_escape($captiontag);
                $columns = intval($columns);
                $itemwidth = $columns > 0 ? floor(100 / $columns) : 100;
                $float = is_rtl() ? 'right' : 'left';
                $selector = "gallery-{$instance}";
                $output = apply_filters('gallery_style', "<div class='slider-tips'><div class='slider-cuerpo'>");
                $i = 0;

                foreach ($attachments as $id => $attachment) {

                    $output .= '<div id="slider-image"><a class="' . $i . '"><img src="' . wp_get_attachment_url($id) . '" border="0"/></a></div>';
                    $i++;
                }
                $output .= "<div class='prev'></div>";
                $output .= "<div class='next'></div>";
                $output .= "</div>";
                $output .= "</div>";
                $output .= "<div class='separador'></div>";
                $output .= "<div class='cuerpo-small-tips'>";
                $output .= "<div class='small-prev'></div>";
                $output .= "<div class='content-small-tips'>";
                $output .= "<ul class='small-tips'>";
                $i = 0;

                foreach ($attachments as $id => $attachment) {

                    $output .= '<li class="small-image-list"><a class="' . $i . '"><img src="' . wp_get_attachment_url($id) . '" height="160" width="150" border="0"/></a></li>';
                    $i++;
                }

                $output .= "</ul>";
                $output .= "</div>";
                $output .= "<div class='small-next'></div>";
                $output .= "</div>";


                $tips = true;
            }
        }
    }

    if (!$tips) {
        $itemtag = tag_escape($itemtag);
        $captiontag = tag_escape($captiontag);
        $columns = intval($columns);
        $itemwidth = $columns > 0 ? floor(100 / $columns) : 100;
        $float = is_rtl() ? 'right' : 'left';
        $selector = "gallery-{$instance}";
        $output = apply_filters('gallery_style', "<div class='slider'>");
        $i = 0;

        foreach ($attachments as $id => $attachment) {

//título
            $titulo = $attachment->post_title;
//caption o leyenda
            $caption = $attachment->post_excerpt;
//texto alt o alternativo
            $alt = get_post_meta($attachment->ID, '_wp_attachment_image_alt', true);
//descripción
            $description = $attachment->post_content;


            $output .= '<div id="slider-image"><a href="#"><img src="' . wp_get_attachment_url($id) . '" width="960" height="340" border="0"></a>
                <div class="texto-slider">
                    <div class="slider-titulo">' . $caption . '</div>
                    <div class="slider-leyenda"></div>
                    <div class="slider-descripcion">' . $description . '</div>
                </div>
        </div>';
        }


        $custom = get_post_custom($post->ID);
        $mostrar_boton = $custom["mostrar-boton"][0];
        $tipo_boton = $custom["tipo-boton"][0];
        $id_prod_comprar = $custom["id_prod_comprar"][0];

        if ($mostrar_boton == 'true') {
            if ($tipo_boton == 'disenios') {
                $output .= '<span class="slider-boton-disenios">
                <a href="http://dev.bepoketprint.com/image/list">Diseños Bepoket Print</a>
                <a href="http://dev.bepoketprint.com/preOrder/list">Usá tus diseños</a>
                </span>';
            } elseif ($tipo_boton == 'consultar') {
                $output .= '<span class="slider-boton-consultar"><a href="' . get_bloginfo("url") . '/?cat=' . get_cat_ID('contacto') . '">CONSULTAR</a></span>';
            } elseif ($tipo_boton == 'comprar') {

                global $query_string;

                $post = new WP_Query($query_string);

                if ($post->have_posts()) {
                    $post->the_post();

                    $nombre_prod = get_the_title();
                }

                $output .= '<span class="slider-boton-comprar">';
                $output .= '<form action="http://dev.bepoketprint.com/product/selectPrice" method="post">';
                $output .= '<input class="nombre-prod" name="n-prod" type="hidden" value="' . $nombre_prod . '">';
                $output .= '<input class="id_prod_sf" name="id" type="hidden" value="' . $id_prod_comprar . '">';
                $output .= '<input class="boton" type="submit" value="COMPRAR">';
                $output .= '</form ></span>';
                //$output .= '<span class="slider-boton-comprar"><a href="' . $link_comprar . '">COMPRAR</a></span>';
            }
        }


//    $output .= '<pre>' . print_r($post) . '</pre>';
        $output .= "</div>";
    }

    return $output;
}

function galeria_tips($output, $attr) {
    global $post, $wp_locale;
    static $instance = 0;
    $instance++;
    if (isset($attr['orderby'])) {
        $attr['orderby'] = sanitize_sql_orderby($attr['orderby']);
        if (!$attr['orderby'])
            unset($attr['orderby']);
    }
    extract(shortcode_atts(array('order' => 'ASC', 'orderby' => 'menu_order ID', 'id' => $post->ID, 'itemtag' => 'dl', 'icontag' => 'dt', 'captiontag' => 'dd', 'columns' => 3, 'size' => 'thumbnail', 'include' => '', 'exclude' => ''), $attr));
    $id = intval($id);
    if ('RAND' == $order)
        $orderby = 'none';
    if (!empty($include)) {
        $include = preg_replace('/[^0-9,]+/', '', $include);
        $_attachments = get_posts(array('include' => $include, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby));
        $attachments = array();
        foreach ($_attachments as $key => $val) {
            $attachments[$val->ID] = $_attachments[$key];
        }
    } elseif (!empty($exclude)) {
        $exclude = preg_replace('/[^0-9,]+/', '', $exclude);
        $attachments = get_children(array('post_parent' => $id, 'exclude' => $exclude, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby));
    } else {
        $attachments = get_children(array('post_parent' => $id, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby));
    }
    if (empty($attachments))
        return '';
    if (is_feed()) {
        $output = "n";
        foreach ($attachments as $att_id => $attachment)
            $output .= wp_get_attachment_link($att_id, $size, true) . "n";
        return $output;
    }



    $itemtag = tag_escape($itemtag);
    $captiontag = tag_escape($captiontag);
    $columns = intval($columns);
    $itemwidth = $columns > 0 ? floor(100 / $columns) : 100;
    $float = is_rtl() ? 'right' : 'left';
    $selector = "gallery-{$instance}";
    $output = apply_filters('gallery_style', "<div class='slider-tips'><div class='slider-cuerpo'>");
    $i = 0;

    foreach ($attachments as $id => $attachment) {

        $output .= '<div id="slider-image"><a class="' . $i . '"><img src="' . wp_get_attachment_url($id) . '" border="0"/></a></div>';
        $i++;
    }
    $output .= "<div class='prev'></div>";
    $output .= "<div class='next'></div>";
    $output .= "</div>";
    $output .= "</div>";
    $output .= "<div class='separador'></div>";
    $output .= "<div class='cuerpo-small-tips'>";
    $output .= "<div class='small-prev'></div>";
    $output .= "<div class='content-small-tips'>";
    $output .= "<ul class='small-tips'>";
    $i = 0;

    foreach ($attachments as $id => $attachment) {

        $output .= '<li class="small-image-list"><a class="' . $i . '"><img src="' . wp_get_attachment_url($id) . '" height="160" width="150" border="0"/></a></li>';
        $i++;
    }

    $output .= "</ul>";
    $output .= "</div>";
    $output .= "<div class='small-next'></div>";
    $output .= "</div>";

    return $output;
}

/* * ******************************************************************************************************************************* */

//Cambiar el logo del login
/* * ******************************************************************************************************************************* */
function my_custom_login_logo() {

    echo '<style type="text/css">

        h1 a {
                background-image: url(' . get_template_directory_uri() . '/images/logo.png) !important;
                background-size: auto 100% !important;
                height: 150px !important;
                margin-bottom: 20px !important;
             }

    </style>';
}

add_action('login_head', 'my_custom_login_logo');

/* * ******************************************************************************************************************************* */

//REGISTRAR SIDEBAR
/* * ******************************************************************************************************************************* */
if (function_exists('register_sidebar')) {
    register_sidebar(array(
        'name' => 'Sidebar newsletter',
        'id' => 'newsletter',
        'before_widget' => '<div id="%1$s" class="widget %2$s">',
        'after_widget' => '</div>',
        'before_title' => '<h3>',
        'after_title' => '</h3>',
    ));
}

/* * ******************************************************************************************************************************* */

//AGREGAR BOTON PASOS AL EDITOR
/* * ******************************************************************************************************************************* */
//function agregar_boton_pasos() {
//// Only do this stuff when the current user has permissions and we are in Rich Editor mode
//    if (( current_user_can('edit_posts') || current_user_can('edit_pages') ) && get_user_option('rich_editing')) {
//        add_filter("mce_external_plugins", "agregar_boton_pasos_plugin");
//        add_filter('mce_buttons', 'registrar_boton_pasos');
//
//        wp_enqueue_style("paso", get_template_directory_uri() . "/css/paso.css");
//    }
//}
//
//function registrar_boton_pasos($buttons) {
//    array_push($buttons, "separator", "BotonAgregarPaso");
//    return $buttons;
//}
//
//// Load the TinyMCE plugin : editor_plugin.js (wp2.5)
//function agregar_boton_pasos_plugin($plugin_array) {
//    $plugin_array['BotonAgregarPaso'] = get_template_directory_uri() . '/js/botonpasos.js';
//    return $plugin_array;
//}
//
//// init process for button control
//add_action('init', 'agregar_boton_pasos');



/* * ******************************************************************************************************************************* */

//Registrar Scripts
/* * ******************************************************************************************************************************* */
function registrarScripts() {
    wp_register_script('jquery2', get_template_directory_uri() . '/js/1.5.1/jquery.min.js', false, false, true);
    wp_register_script('jquery-cookie', get_template_directory_uri() . '/js/jquery.cookie.js', false, false, true);
    wp_register_script('pie', get_template_directory_uri() . '/js/PIE.js', false, false, true);
    wp_register_script('custom_animations', get_template_directory_uri() . '/js/custom_animations.js', false, false, true);
    wp_register_script('custom_easing', get_template_directory_uri() . '/js/custom_easing.js', false, false, true);
    wp_register_script('jslider', get_template_directory_uri() . '/js/jSlider.js', false, false, true);
    wp_register_script('menu', get_template_directory_uri() . '/js/menu.js', false, false, true);
    wp_register_script('general', get_template_directory_uri() . '/js/general.js', false, false, true);
    wp_register_script('ideas', get_template_directory_uri() . '/js/ideas.js', false, false, true);
    wp_register_script('slider-tips', get_template_directory_uri() . '/js/slider-tips.js', false, false, true);
    wp_register_script('suscriptores', get_template_directory_uri() . '/js/suscriptores.js', false, false, true);

    wp_localize_script('ideas', 'ajax_object', array('ajax_url' => admin_url('admin-ajax.php')));
    wp_localize_script('menu', datosServ, array('template_url' => get_template_directory_uri()));
}

add_action('init', 'registrarScripts');

function cargarScripts() {
    wp_enqueue_script('jquery2');
    wp_enqueue_script('jquery-cookie');
    wp_enqueue_script('pie');
    wp_enqueue_script('custom_animations');
    wp_enqueue_script('custom_easing');
    wp_enqueue_script('jslider');
    wp_enqueue_script('menu');
    wp_enqueue_script('general');
    wp_enqueue_script('ideas');
    wp_enqueue_script('slider-tips');
    wp_enqueue_script('suscriptores');
}

add_action('wp_footer', 'cargarScripts');



/* * ******************************************************************************************************************************* */
/* 	Registrar Menus WP3.0+
  /********************************************************************************************************************************* */
if (function_exists('register_nav_menus')) { //To add support for navigation menus
    register_nav_menus(
            array(
                'MenuPrincipal' => __('Menu Principal'),
                'MenuIdeas' => __('Menu Ideas'),
                'MenuConsejos' => __('Menu Consejos'),
                'MenuAcerca-de' => __('Menu Acerca de'),
                'MenuFooter' => __('Menu Footer')
            )
    );
}



/* * ******************************************************************************************************************************* */
/* 	Configurar Imágenes Thumbnails WP2.9+
  /********************************************************************************************************************************* */
if (function_exists('add_theme_support')) {
    add_theme_support('post-thumbnails');
    add_image_size('video-thumbnail', 66, 56, true); // Category list thumbnails
    add_image_size('index-thumbnail', 220, 180, true);
    add_image_size('slider-thumbnail', 940, 474, true);
    add_image_size('blog-thumbnail', 0, 0, true);
    add_image_size('popup-ideas', 300, 400, true);
    add_image_size('partners-thumbnail', 290, 0, true);
    add_image_size('corporate-partners-thumbnail', 84, 0, true);
    add_image_size('idea-tarjeta-caja-thumbnail', 300, 150, true);
    add_image_size('custom', 155, 0, true);
}

/* * ******************************************************************************************************************************* */

//quitar menus de admin
/* * ******************************************************************************************************************************* */
function quitar_menus() {
    global $menu;
    $restricted = array(__('Pages'));

    end($menu);
    while (prev($menu)) {
        $value = explode(' ', $menu[key($menu)][0]);
        if (in_array($value[0] != NULL ? $value[0] : "", $restricted)) {
            unset($menu[key($menu)]);
        }
    }
}

add_action('admin_menu', 'quitar_menus');



/* * ******************************************************************************************************************************* */

// Obtener la URL de la página actual
/* * ******************************************************************************************************************************* */


function getCurrentUrl() {

    $domain = $_SERVER['HTTP_HOST'];

    $url = "http://" . $domain . $_SERVER['REQUEST_URI'];

    return $url;
}

/* * ******************************************************************************************************************************* */

// Function obtener menus
/* * ******************************************************************************************************************************* */
function custom_obtener_menus($menu_name, $menu_item_name, $sub_menu_item_name) {// $menu_name se refiere al slug del menu
    if (($locations = get_nav_menu_locations()) && isset($locations[$menu_name])) {
        $menu = wp_get_nav_menu_object($locations[$menu_name]);
        $menu_items = wp_get_nav_menu_items($menu->term_id); //Obtengo el Menú
//        echo '<pre>';
//        print_r($menu_items);
//        echo '</pre>';
        $rango = array(0 => "0");
//Armo la estructura del HMTL
        $menu_list = '<div class = "' . $menu_name . '">' . "\n";

        if ($_GET['custom_page']) {
            global $query_string;

            $post = new WP_Query($query_string);

            if ($post->have_posts()) {
                $post->the_post();

                if ($menu_name == 'MenuPrincipal') {
                    $menu_list .= '<span id = "titulo-post">' . get_the_title() . '</span>' . "\n";
                }
            }
            wp_reset_postdata();
        }

        $ID_ant = 0;

//        echo '<pre>';
//        print_r($menu_items);
//        echo '</pre>';      



        foreach ((array) $menu_items as $key => $menu_item) {
            $ID_padre = $menu_item->menu_item_parent; //obtengo el ID del menu padre
            $ID = $menu_item->ID; // Obtengo el ID del menu actual

            $rango{$ID} = $rango{$ID_padre} + 1; // Obtengo el rango del menu (empieza en rango 1)

            $title = $menu_item->title;
            $url = $menu_item->url;

//Determinar si es el menu activo
            $activo = "";
            if (getCurrentUrl() == $url) {
                $activo = "activo";
            }


            if ($rango{$ID} == 1 && $rango{$ID} > $rango{$ID_ant}) {
                $menu_list .= "\t\t\t\t" . '<ul id = "R-' . $rango{$ID} . '" class = "' . $menu_item_name . ' ' . $ID_padre . '">' . "\n";
                $menu_list .= "\t\t\t\t\t" . '<li id = "' . $ID . '" class = "R-' . $rango{$ID} . ' ' . $activo . '" ' . $menu_item->post_excerpt . '><a href = "' . $url . '">' . $title . '</a>';
            } elseif ($rango{$ID} != 1 && $rango{$ID} > $rango{$ID_ant}) {
                $menu_list .= "\t\t\t\t" . '<ul id = "R-' . $rango{$ID} . '" class = "' . $sub_menu_item_name . ' ' . $ID_padre . '">' . "\n";
                if (($menu_name == 'MenuIdeas' || $menu_name == 'MenuAcerca-de') && $rango{$ID} >= 2) {
                    $menu_list .= "\t\t\t\t\t" . '<li id = "' . $ID . '" class = "R-' . $rango{$ID} . ' ' . $activo . '" ' . $menu_item->post_excerpt . '><a href = "' . $url . '">' . '- ' . $title . '</a>';
                } else {
                    $menu_list .= "\t\t\t\t\t" . '<li id = "' . $ID . '" class = "R-' . $rango{$ID} . ' ' . $activo . '" ' . $menu_item->post_excerpt . '><a href = "' . $url . '">' . $title . '</a>';
                }
            } elseif ($rango{$ID} == $rango{$ID_ant}) {
                $menu_list .='</li>' . "\n";
                if (($menu_name == 'MenuIdeas' || $menu_name == 'MenuAcerca-de') && $rango{$ID} >= 2) {
                    $menu_list .= "\t\t\t\t\t" . '<li id = "' . $ID . '" class = "R-' . $rango{$ID} . ' ' . $activo . '" ' . $menu_item->post_excerpt . '><a href = "' . $url . '">' . '- ' . $title . '</a>';
                } else {
                    $menu_list .= "\t\t\t\t\t" . '<li id = "' . $ID . '" class = "R-' . $rango{$ID} . ' ' . $activo . '" ' . $menu_item->post_excerpt . '><a href = "' . $url . '">' . $title . '</a>';
                }
            } else {

                $aux = $rango{$ID_ant} - $rango{$ID};
                for ($i = 0; $i < $aux; $i++) {
                    $menu_list .='</li>' . "\n";
                    $menu_list .= "\t\t\t\t" . '</ul>' . "\n";
                }

                $menu_list .= "\t\t\t\t\t" . '<li id = "' . $ID . '" class = "R-' . $rango{$ID} . ' ' . $activo . '" ' . $menu_item->post_excerpt . '><a href = "' . $url . '">' . $title . '</a>';
            }

            $ID_ant = $ID;
        }

        $aux = $rango{$ID_ant} - $rango{$ID};
        for ($i = 0; $i < $aux; $i++) {
            $menu_list .='</li>' . "\n";
            $menu_list .= "\t\t\t\t" . '</ul>' . "\n";
        }

        $menu_list .= "\t\t\t\t" . '</ul>' . "\n";
        $menu_list .= "\t\t\t" . '</div>' . "\n";
    } else {
// $menu_list = '<!--no list defined-->';
    }

    echo "$menu_list";
}

//Funcion para agregar script mostrar_ocultar_cajas
function agregar_scripts($hook) {

    global $post;
//Verificamos que estamos en la edicion del post
    if ($hook == 'post-new.php' || $hook == 'post.php') {
        if ("cajas" == $post->post_type) {
            wp_enqueue_script('animaciones_cajas');

            wp_localize_script('animaciones_cajas', 'ajax_object', array('ajax_url' => admin_url('admin-ajax.php')));
        }
    }
}

add_action("admin_enqueue_scripts", "agregar_scripts");

/* * ******************************************************************************************************************************* */

// Mostrar Mensaje de Sitio en Construcción
/* * ******************************************************************************************************************************* */

function sitioEnConstruccion() {
    ?>

    <style type="text/css">
        .edit-link.button {
            float: right;
            background-color: #21759B;
            border-radius: 4px 4px 4px 4px;
            box-shadow: 0 0 4px;
        }

        .edit-link.button:hover {
            background-color: #289BCC;
            cursor: pointer;
        }

        .edit-link.button a{
            color: #FFFFFF;
            display: block;
            padding: 5px 15px;
            text-decoration: none;
            text-shadow: 0 1px 0 rgba(0, 0, 0, 0.1);
        }
    </style>

    <div class="sitio-en-constuccion" style="display: block; margin: 50px 295px;">

        <h2 style="text-align: center;">Sitio en Construcción</h2>
        <img src="<?php bloginfo("template_url"); ?>/images/en-construccion.jpg" alt="sitio en construccion" width="300" />

    <?php edit_post_link(__('Editar'), '<span class="edit-link button">', '</span>'); ?>
    </div>
    <?php
}

//FUNCION WORDPRESS PARA SABER SI LA CATEGORIA ACTUAL ES HIJA DE
if (!function_exists('obtener_id_categorias')) {

    function obtener_id_categorias($cat_padre) {
        $categorias[] = get_cat_ID($cat_padre);
        foreach (get_categories(array('child_of' => get_cat_ID($cat_padre), 'hide_empty' => 0)) as $cat) {
            $categorias[] = $cat->cat_ID;
//            $categorias .= ", " . $cat->slug;
        }

        return $categorias;
    }

}

if (!function_exists('post_is_in_descendant_category')) {

    function post_is_in_descendant_category($cats, $_post = null) {
        foreach ((array) $cats as $cat) {
// get_term_children() accepts integer ID only
            $descendants = get_term_children((int) $cat, 'category');
            if ($descendants && in_category($descendants, $_post))
                return true;
        }
        return false;
    }

}

//cant de caract a mostrar en los post
function excerpt($limit) {
    $excerpt = explode(' ', get_the_content(), $limit);
    if (count($excerpt) >= $limit) {
        array_pop($excerpt);
        $excerpt = implode(" ", $excerpt) . '…';
    } else {
        $excerpt = implode(" ", $excerpt);
    }
    $excerpt = preg_replace('`\[[^\]]*\]`', '', $excerpt);
    return $excerpt;
}

//cant de caract a mostrar en los post
function resumen($texto, $cant_pal) {
    $excerpt = explode(' ', $texto, $cant_pal);
    if (count($excerpt) >= $cant_pal) {
        array_pop($excerpt);
        $excerpt = implode(" ", $excerpt) . '…';
    } else {
        $excerpt = implode(" ", $excerpt);
    }
    $excerpt = preg_replace('`\[[^\]]*\]`', '', $excerpt);
    return $excerpt;
}

function paginado() {
    global $wp_query, $wp_rewrite;
    $wp_query->query_vars['paged'] > 1 ? $current = $wp_query->query_vars['paged'] : $current = 1;

    $pagination = array(
        'base' => @add_query_arg('page', '%#%'),
        'format' => '',
        'total' => $wp_query->max_num_pages,
        'current' => $current,
        'show_all' => true,
        'type' => 'list',
        'next_text' => '&raquo;',
        'prev_text' => '&laquo;'
    );

    if ($wp_rewrite->using_permalinks())
        $pagination['base'] = user_trailingslashit(trailingslashit(remove_query_arg('s', get_pagenum_link(1))) . 'page/%#%/', 'paged');

    if (!empty($wp_query->query_vars['s']))
        $pagination['add_args'] = array('s' => get_query_var('s'));

    echo paginate_links($pagination);
}

function obtener_id_productos($cant = '1') {
    query_posts("post_type=cajas&posts_per_page=-1&orderby=rand");

    $i = 1;
    while (have_posts()) : the_post();
        if ($i <= $cant) {
            $custom = get_post_custom(get_the_ID());
            $tipo_caja = $custom["tipo_caja"][0];
            $producto = $custom["producto-Cproducto"][0];
            $dimension = $custom["dimension-Cproducto"][0];

            if ($tipo_caja == 'caja-producto' && $dimension != 0 && $producto != 0) {
                $ids_productos[] = get_the_ID();
                $i++;
            }
        }

    endwhile;

    return $ids_productos;
}

include_once 'customs/clase_paginas.php';
include_once 'customs/clase_cajas.php';
include_once 'customs/clase_ideas.php';
include_once 'customs/clase_parametros.php';
?>